package com.modelscope.ai.exception;


import com.modelscope.ai.domain.entity.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    //全局异常处理
    @ExceptionHandler(Exception.class)
    public R<String> error(Exception e) {
        log.error("进行了全局处理", e);
        return R.error("执行了全局异常处理");
    }

    @ExceptionHandler(BusinessException.class)
    public R<?> error(BusinessException e) {
        log.error("进行了全局处理", e);
        return new R<>(999, e.getMsg(), e.getMsg());
    }

    //特定异常处理
    @ExceptionHandler(ArithmeticException.class)
    public R<String> error2(ArithmeticException e) {
        log.error(e.getMessage(), e);
        return R.error("ArithmeticException算数异常");
    }

}
